Skip to content

feat: Add temp dir option#2891

Merged
vmaerten merged 6 commits into
go-task:mainfrom
kjasn:main
Jun 29, 2026
Merged

feat: Add temp dir option#2891
vmaerten merged 6 commits into
go-task:mainfrom
kjasn:main

Conversation

@kjasn

@kjasn kjasn commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Close #998

Support temp-dir option in .taskrc.yml and env variable. Haven't supported option or configuration in dotenv and Taskfile.yml due to some file reading order issues.

AI helped with generating some unit test in this PR.

Copilot AI review requested due to automatic review settings June 26, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for configuring Task’s temporary directory via .taskrc.yml (temp-dir) and the TASK_TEMP_DIR environment variable, wiring the resolved value into executor setup and updating docs/schemas accordingly.

Changes:

  • Add temp-dir to taskrc AST + merge logic, and add unit tests covering parsing/merge precedence.
  • Introduce Executor.TempDirPath / WithTempDirPath and use it during Executor setup to build Executor.TempDir.
  • Update website docs and JSON schema for .taskrc.yml, plus VS Code YAML schema mapping.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/src/public/schema-taskrc.json Adds temp-dir to the taskrc JSON schema.
website/src/docs/reference/config.md Documents the new temp-dir config option and adds it to the example config.
taskrc/taskrc_test.go Adds tests for temp-dir parsing and merge precedence across config locations.
taskrc/ast/taskrc.go Adds TempDir field and merges it during TaskRC merge.
setup.go Adds temp-dir resolution helper and uses it to initialize Executor.TempDir.
internal/flags/flags.go Reads temp-dir from env/taskrc into executor options (no CLI flag).
executor.go Adds TempDirPath + WithTempDirPath option for unresolved temp dir configuration.
.vscode/settings-sample.json Adds YAML schema association for .taskrc.* files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/flags/flags.go Outdated
Comment thread setup.go Outdated
Comment on lines +131 to +140
func (e *Executor) configuredTempDirPath() string {
// Priority: OS env > taskrc/env > default
if tempDir := env.GetTaskEnv("TEMP_DIR"); tempDir != "" {
return tempDir
}
if e.TempDirPath != "" {
return e.TempDirPath
}
return ".task"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precedence behavior is same as internal/flags/flags.go:319:

// getConfig extracts a config value with priority: env var > taskrc config > fallback
func getConfig[T any](config *taskrcast.TaskRC, envKey string, fieldFunc func() *T, fallback T) T {
// xxx
};

Comment thread setup.go Outdated
Comment on lines +131 to +135
func (e *Executor) configuredTempDirPath() string {
// Priority: OS env > taskrc/env > default
if tempDir := env.GetTaskEnv("TEMP_DIR"); tempDir != "" {
return tempDir
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has some file reading order issue, so it doesn't support this for now.

@vmaerten vmaerten self-requested a review June 29, 2026 13:51
kjasn and others added 6 commits June 29, 2026 16:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Register --temp-dir as a real pflag instead of assigning the variable
directly in the flags package, so it follows the same flag+config pattern
as every other option (e.g. --remote-cache-dir).

Drop the configuredTempDirPath helper: now that the flags layer owns env
resolution (like every other option), it collapses to cmp.Or(TempDirPath,
".task"), inlined into setupTempDir. This also fixes the previous inverted
precedence where TASK_TEMP_DIR was read above the resolved path and would
win over the flag.

Document the --temp-dir flag in the CLI reference.

@vmaerten vmaerten left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've added the CLI support as well

@vmaerten vmaerten enabled auto-merge (squash) June 29, 2026 14:11
@vmaerten vmaerten merged commit 1c743de into go-task:main Jun 29, 2026
14 checks passed
@kjasn

kjasn commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I've added the CLI support as well

At first I thought this should only be a fixed setting, so I didn't plan to add CLI support to it. Anyway, it also makes sense👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure that TASK_TEMP_DIR is considered if set on the .env file

3 participants